/**
 * Validatious 2.0
 * Christian Johansen (christian@cjohansen.no)
 *
 * Idéer og skisser
 *
 */

// Validate single field
v2.validate("field".is("required")); // OK

// Validate field with single param
v2.validate("name".has("min-length", 5)); // OK

// Validate field with single parameter and message
v2.validate("name".has("min-length", 5).explain("Atleast 5 characters")); // OK

// Validate field with several validators
v2.validate("name".is("required").and("alpha")); // OK

//v2.validate("name".is("required").and("alhpa").withName("Name"))

// Validate field with several validators, and parameters
v2.validate("name".is("required").andHas("min-length", 3)); // OK

// Validate field with several validators, but one global error message
v2.validate("name".is("required").and("alpha").help("Please, it's required to be an alpha")); // OK

// a && b
v2.validate("name".is("required"), "email".is("required")); // OK
v2.validateAll("name".is("required"), "email".is("required")); // OK
v2.validate(v2.and("name".is("required"), "email".is("required"))); // OK
v2.dsl.expose(); // OK
validate(and("name".is("required"), "email".is("required"))); // OK

// a && b && c
validate(
  "name".is("required"),
  "email".has("min-length", 3).explain("Gimme emails"),
  "phone".is("required")
); // OK

// a || b || c
v2.validateAny(
  "name".is("required"),
  "email".has("min-length", 3).explain("Gimme emails"),
  "phone".is("required")
); // OK

// (a && b) || c
validate(
  or(
    and(
      "name".is("required"),
      "email".is("required")
    ),
    "phone".has("min-length", 4)
  )
); // OK

validateAny(
  and(
    "name".is("required"),
    "email".is("required")
  ),
  "phone".has("min-length", 4)
); // OK

// (a && b) || c
validate(
  or(
    and(
      "name".is("required"),
      "email".is("required")
    ).explain("We need name or email"),
    "phone".has("min-length", 4)
  )
); // OK

/* Not yet ...
var email = "email".is("required").andIsAn("email");
var name = "name".is("required").whenInvalid(email);
validate(email, name);
*/
